<template>
  <div>
    <a-modal
      v-model="visible"
      title="数据详情"
      :width="1000"
      :footer="null"
      @cancel="onCancel"
    >
      <s-table
        bordered
        ref="table"
        size="middle"
        :row-key="(record) => record.cb_id"
        :columns="businessColumns"
        :data="businessData"
      >
        <template slot="contract_no" slot-scope="text,record">
          <a @click="toContractDetail(record.contract_id)">{{ text }}</a>
          <br>
          <a @click="toBusinessDetail(record.cb_id)">{{ record.business_no }}</a>
        </template>
        <template slot="price" slot-scope="text">
          <div class="price" style="line-height: 30px">
            <a-tag color="red">价格￥{{ text }}</a-tag>
            <br>
            <a-tag color="red">官费￥{{ text }}</a-tag>
          </div>
        </template>
      </s-table>
    </a-modal>
  </div>
</template>

<script>
  import { STable } from '@/components'
  import advcolumns from '@/columns/adviser'
  import { getBusinessList } from '@/api/adviser'
  import moment from 'moment'

  export default {
    props: {
      businessId: {
        type: String,
        default: ''
      },
      title: {
        type: String,
        default: ''
      },
      month: {
        type: String,
        default: ''
      }
    },
    components: {
      STable
    },
    name: 'BusinessModal',
    data () {
      return {
        visible: true,
        businessColumns: advcolumns.business_columns,
        businessData: parameters => {
          return getBusinessList(Object.assign(parameters, this.queryParam)).then(res => {
            return res.result
          })
        },
        queryParam: {}
      }
    },
    created () {
      this.queryParam['business_id'] = this.businessId
      if (this.month !== '') {
        this.queryParam['month'] = moment(moment(this.month, 'YYYY-MM')).format('YYYY-MM')
      }
    },
    methods: {
      toContractDetail (id) {
        this.$router.push({ name: 'ContractDetail', params: { cid: id } })
      },
      toBusinessDetail (id) {
        this.$router.push({ name: 'BusinessDetail', params: { id } })
      },
      onCancel () {
        this.visible = false
        this.$emit('cancel', this.visible)
      }
    }
  }
</script>

<style scoped>

</style>
